import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import AppComponents from 'components/App';
import { LocaleProvider } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';
import enUS from 'antd/lib/locale-provider/en_US';
import jaJP from 'antd/lib/locale-provider/ja_JP';
import zhTW from 'antd/lib/locale-provider/zh_TW'
import moment from 'moment'

class App extends Component {
  render() {
    const { actions, language } = this.props;
    let locale;
    switch(language.locale){
      case 'zh':
        locale = zhCN;
        moment.locale('zh-cn');
        break;
      case 'ja_jp':
        locale = jaJP;
        moment.locale('ja');
        break;
      case 'zh_TW':
        locale = zhTW;
        moment.locale('zh-tw');
        break;
      default:
        locale = enUS;
        moment.locale('en-nz');
        break;
    }
    return (
      <LocaleProvider locale={locale}>
          <AppComponents actions={actions} />
      </LocaleProvider>
    );
  }
}

App.propTypes = {
  actions: PropTypes.shape({})
};

function mapStateToProps(state) {
  return {
    language: state.main.language
  };
}

function mapDispatchToProps(dispatch) {
  const actions = {};
  return { actions: bindActionCreators(actions, dispatch) };
}
export default connect(mapStateToProps, mapDispatchToProps)(App);
